﻿@model DLM.Domain.Model.User
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.form.js")"></script>
<script type="text/javascript">
    $(document).ready(function () {

        var options = {
            target: '#divUserInfo',
            success: showResponse

        };
        $('#userinfo').submit(function () {
            $(this).ajaxSubmit(options);
            return false;
        });

        $("#txtBirthday").datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, minDate: null, maxDate: null, yearRange: 'c-50:c+20', onSelect: function (dateText, inst) { calculateAge(dateText); } });
    });


    function calculateAge(dateText) {
        var now = new Date();
        var birthday = parseDate(dateText);
        var age = now.getFullYear() - birthday.getFullYear();
        $("#txtAge").val(age-1);
    }

    function parseDate(str) {
        if (typeof str == 'string') {
            var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);
            if (results && results.length > 3)
                return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]));
            results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);
            if (results && results.length > 6)
                return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]));
            results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);
            if (results && results.length > 7)
                return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]), parseInt(results[7]));
        }
        return null;
    }

    function showRequest(formData, jqForm, options) {

        return true;
    }
    function showResponse(responseText, statusText) {
        //alert(responseText);
        if (responseText != "") {
            ShowDialogMessage("warn", responseText);
            $("#divUserInfo").load("/User/UserEdit/@Model.UserID")

        } else {

            ShowDialogMessage("right", "更新成功！");
            var request = $.ajax({
                type: "GET",
                url: "/User/UserEdit/",
                data: { id: "@Model.UserID" },
                success: function (data, textStatus) {
                    $("#divUserInfo").html(data);
                },
                error: function () {
                }
            }).done(function (msg) {
            });
        }


    }

</script>

@using (Html.BeginForm("UserEdit", "User", FormMethod.Post, new { enctype = "multipart/form-data", id = "userinfo" }))
{

    <div  class="main_tab_2_down">
        <div class="box">
            <h3>
                基本资料</h3>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>&nbsp;</label>
                <div class="info">
                    @Html.ValidationSummary(true, "用户信息修改失败，请重试！")
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>姓名</label>
                <div class="info">
                    @Html.HiddenFor(m => m.UserID)
                    @Html.TextBoxFor(m => m.Name, new { @class = "text" })
                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "va" })
                   
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>头像</label>
                <div class="info">
                    @if (Model != null && !string.IsNullOrEmpty(Model.Photo) && Model.Photo != "none_75_75.png")
                    {
                        <img src="@Url.Content("~/Files/Photos/" + Model.UserID + "/Title/" + Model.Photo)" alt="头像" />
                    }
                    else
                    { 
                        <img src="@Url.Content("~/Content/ad/none_75_75.png")" style="border:1px solid #ff0000;" alt="头像" />
                    }
                     <div class="va">
                       务必上传真实照片，否则可能会被剥夺会员资格</div>
                       <div class="va">
                       只允许不超过4MB大小的.JPEG格式的头像</div>
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>&nbsp;</label>
                <div class="info">
                    <input type="file" name="uploadFile" />
                     <span>点击页面下方'提交修改'按钮方能生效</span>
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>性别</label>
                <div class="info">
                    @{
                    var list = new List<SelectListItem> 
                        { new SelectListItem { Text = "请选择", Value = "0" },
                            new SelectListItem { Text = "男", Value = "False" },
                            new SelectListItem { Text = "女", Value = "True" }
                        };


                    if (Model.Gender.HasValue)
                    {
                        if (Model.Gender.Value)
                        {
                            list[2].Selected = true;
                        }
                        else
                        {
                            list[1].Selected = true;
                        }
                    }
                    
                    }
                    @Html.DropDownListFor(model => model.Gender, list, new { @class = "sel" })
                    @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "va error" })
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>出生年月</label>
                <div class="info">
                    @if (!Model.Birthday.HasValue)
                    {
                         @Html.TextBoxFor(m => m.Birthday, new { @class = "input-validation-error", id = "txtBirthday", maxlength = 20 })
                    }
                    else
                    {
                         @Html.TextBoxFor(m => m.Birthday, new { @class = "text", id = "txtBirthday", maxlength = 20 })
                    }
                   
                    @Html.ValidationMessageFor(m => m.Birthday, "", new { @class = "va error" })
                </div>
            </div>
                   <div class="tr clearfix">
                <label class="lb">
                    <s></s>年龄</label>
                <div class="info">
                    @Html.TextBoxFor(m => m.Age, new { @class = "text", id = "txtAge", maxlength = 8 })
                    @Html.ValidationMessageFor(m => m.Age, "", new { @class = "va error" })
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>现居地</label>
                <div class="info">
      @*              @if (string.IsNullOrEmpty(Model.Location))
                    {
                        
                      @Html.TextBoxFor(m => m.Location, new { @class = "input-validation-error", maxlength = 18  })<br />
                    }
                    else
                    { 
                          @Html.TextBoxFor(m => m.Location, new { @class = "text", maxlength = 18 })<br />
                    }*@
                  
           
                    @{ Html.RenderPartial("_LocationSelection", ViewData["CurrentLocation"] as DLM.Web.ViewModel.LocationSelectionPageView);}
                    @Html.ValidationMessageFor(m => m.Location, "", new { @class = "va error" })</div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>籍贯</label>
                <div class="info">
       @*             @if (string.IsNullOrEmpty(Model.NativePlace))
                    {
                      @Html.TextBoxFor(m => m.NativePlace, new { @class = "input-validation-error", maxlength = 16 })
                    }
                    else
                    { 
                           @Html.TextBoxFor(m => m.NativePlace, new { @class = "text", maxlength = 16 })
                    }*@
       
                    @{ Html.RenderPartial("_NativeSelection", ViewData["CurrentNative"] as DLM.Web.ViewModel.NativeSelectionPageView);}
                    @Html.ValidationMessageFor(m => m.NativePlace, "", new { @class = "va error" })</div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>婚姻状况</label>
                <div class="info">
                    @{
                       List<SelectListItem> marriageList = new List<SelectListItem> 
                        { new SelectListItem { Text = "请选择", Value = "" },
                            new SelectListItem { Text = "未婚", Value = "未婚" },
                            new SelectListItem { Text = "已婚", Value = "已婚" },
                             new SelectListItem { Text = "离异", Value = "离异" }
                            
                };

                       foreach (var marriageItem in marriageList)
                       {
                           if (marriageItem.Text == Model.Marriage)
                           {
                               marriageItem.Selected = true;
                           }
                       }
                    }

                    @if (string.IsNullOrEmpty(Model.Marriage) || Model.Marriage == "请选择")
                    {
                           @Html.DropDownListFor(m => m.Marriage, marriageList, new { @class = "select-validation-error" })
                    }
                    else
                    {
                       @Html.DropDownListFor(m => m.Marriage, marriageList, new { @class = "select" })
                    }
                 
                    @Html.ValidationMessageFor(model => model.Marriage, "", new { @class = "va error" })
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>身高</label>
                <div class="info">
                    @if (string.IsNullOrEmpty(Model.Stature))
                    {
                         @Html.TextBoxFor(m => m.Stature, new { @class = "input-validation-error", maxlength = 10 })
                    }
                    else
                    { 
                         @Html.TextBoxFor(m => m.Stature, new { @class = "text t_1", maxlength = 10 })
                    }
                   
                    厘米
                    @Html.ValidationMessageFor(m => m.Stature, "", new { @class = "va error" })
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>体重</label>
                <div class="info">
                  @if (!Model.Weight.HasValue)
                  {
                        @Html.TextBoxFor(m => m.Weight, new { @class = "input-validation-error", maxlength = 8 }) <span>公斤</span>
                  }
                  else
                  {
                        @Html.TextBoxFor(m => m.Weight, new { @class = "text t_1", maxlength = 8 }) <span>公斤</span>
                  }
                  
                    @Html.ValidationMessageFor(m => m.Weight, "", new { @class = "va error" })</div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>学历</label>
                <div class="info">
                    @{
                  List<SelectListItem> eduList = new List<SelectListItem> 
    {new SelectListItem { Text = "请选择", Value = "" },
        new SelectListItem{ Text="高中",Value="高中"},
        new SelectListItem{ Text="大专",Value="大专"},
        
           new SelectListItem{Text="本科",Value="本科"},new SelectListItem{ Text="硕士",Value="硕士"},new SelectListItem{ Text="博士",Value="博士"},
    };
                  foreach (var eduItem in eduList)
                  {
                      if (Model.Education == eduItem.Value)
                      {
                          eduItem.Selected = true;
                      }
                  }
                    }

                    @if (string.IsNullOrEmpty(Model.Education) || Model.Education == "请选择")
                    {
                          @Html.DropDownListFor(m => m.Education, eduList, new { @class = "select-validation-error" })
                    }
                    else
                    { 
                          @Html.DropDownListFor(m => m.Education, eduList, new { @class = "sel" })
                    }
                  
                    @Html.ValidationMessageFor(m => m.Education, "", new { @class = "va error" })</div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>工作</label>
                <div class="info">
                    @if (string.IsNullOrEmpty(Model.Job))
                    {
                         @Html.TextBoxFor(m => m.Job, new { @class = "input-validation-error", maxlength = 20 })
                    }
                    else
                    {
                         @Html.TextBoxFor(m => m.Job, new { @class = "text", maxlength = 20 }) 
                    }
                   
                    @Html.ValidationMessageFor(m => m.Job, "", new { @class = "va error" })
                </div>
            </div>
            <div class="tr clearfix">
                <label class="lb">
                    <s></s>月收入(税前)</label>
                <div class="info">
                    @{
                    List<SelectListItem> incomeList = new List<SelectListItem> 
    {new SelectListItem { Text = "请选择", Value = "" },
        new SelectListItem{ Text="5000及以下",Value="5000及以下"},
           new SelectListItem{Text="5000-10000",Value="5000-10000"},new SelectListItem{ Text="10000-20000",Value="10000-20000"},
           new SelectListItem{ Text="20000以上",Value="20000以上"}
    };
                    foreach (var incomItem in incomeList)
                    {
                        if (Model.Education == incomItem.Value)
                        {
                            incomItem.Selected = true;
                        }
                    }
                    }
                    @if (string.IsNullOrEmpty(Model.Income) || Model.Income == "请选择")
                    {
                          @Html.DropDownListFor(m => m.Income, incomeList, new { @class = "select-validation-error" })
                    }
                    else
                    {
                          @Html.DropDownListFor(m => m.Income, incomeList, new { @class = "sel" })
                    }
                  
                    @Html.ValidationMessageFor(m => m.Income, "", new { @class = "va error" })
                    @* @Html.TextBoxFor(m => m.Income, new { @class = "text" })*@</div>
            </div>
                <div class="tr clearfix">
        <label class="lb">
            <s></s>手机号码</label>
        <div class="info">
            @if (string.IsNullOrEmpty(Model.Phone))
            {
                  @Html.TextBoxFor(m => m.Phone, new { @class = "input-validation-error", maxlength = 15 })
            }
            else
            {
                  @Html.TextBoxFor(m => m.Phone, new { @class = "text", maxlength = 15 })
            }
          
            @Html.ValidationMessageFor(m => m.Phone, "", new { @class = "va error" })
        </div>
    </div>
            <div class="tr clearfix btn">
                <label class="lb">
                    <s></s>&nbsp;</label>
                <div class="info">
                    <input type="submit" value="" class="edit_info" /></div>
            </div>
        </div>
    </div>
}